/**
 * Author: Shen Yanqiu
 * Date: 2018-02-26
 * Time: 18:16
 *
 */
import React from 'react';
import { Page } from 'components';
import TopOperation from 'components/TopOperation';
import { connect } from 'dva';
import PropTypes from 'prop-types';
import { Row, Col, Table } from 'antd';
import styles from './style.less';
import { Link } from 'react-router-dom';
import { routerRedux } from 'dva/router';
import {routerTool} from "../../../router/routerTool";

const settings = {
  designation: true, // 名称输入框
  status: false, // 状态选择框
  ownership: false, // 所属选择框
  section: false, // 部门选择框
  starlevel: false, // 星级选择框
  object: false, // 对象选择框
  time: false, // 时间选择框
}

class SatisfactionStatisticsList extends React.Component {
  static propTypes = {
    loading: PropTypes.object,
    satisfactionStatisticsList: PropTypes.object,
    dispatch: PropTypes.func,
  };
  render () {
    const { loading, satisfactionStatisticsList, dispatch } = this.props;
    const { list, pagination } = satisfactionStatisticsList;
    const SearchData = (data) => {
      dispatch({
        type: 'satisfactionStatisticsList/searchData',
        payload: {
          formData: data,
        },
      });
    };
    const nameClickHandler = (id) => {
      dispatch(routerTool.redirectTo({
        name: 'SatisfactionStatisticsDetails',
        params: {
          id,
        },
      }));
    };
    const _getColumnConfig = () => {
      return [{
        width: 180,
        title: '名称',
        dataIndex: 'username',
        key: 'username',
        render: (text, record) => {
          return (
            <div onClick={() => nameClickHandler(record.id)} className={styles.NameClickBlock}>
              <span>{ text }</span>
            </div>
          );
        },
      }, {
        width: 700,
      }, {
        width: 200,
        title: '时间',
        dataIndex: 'time',
        key: 'time',
      }, {
        width: 100,
        title: '操作',
        key: 'operation',
        render: (text, record) => {
          return (
            <div onClick={() => nameClickHandler(record.id)} className={styles.LinkStyle}>
              查看
            </div>
          );
        }
      }];
    };
    const tableProps = {
      loading: loading.effects['satisfactionStatisticsList/loadTableList'],
      columns: _getColumnConfig(),
      dataSource: list,
      pagination,
      rowKey: r => r.id,
      onChange (_pagination) {
        dispatch({
          type: 'satisfactionStatisticsList/loadTableList',
          payload: {
            current: _pagination.current,
            pageSize: _pagination.pageSize,
          },
        });
      },
    };
    return (
      <Page loading={loading.effects['satisfactionStatisticsList/firstLoad']}>
        <TopOperation {...settings} SearchData={SearchData} />
        <Row className={styles.satisfactionStatisticsList}>
          <Col>
            <Table
              {...tableProps}
            />
          </Col>
        </Row>
      </Page>
    );
  }
}
export default connect(({ loading, satisfactionStatisticsList }) => ({ loading, satisfactionStatisticsList }))(SatisfactionStatisticsList);
